package com.ethink.platform.controller.system;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.system.api.SystemOrganizationFacade;
import com.ethink.system.api.info.SystemOrganizationInfo;
import com.ethink.system.api.request.OrganizationAddRequest;
import com.ethink.system.api.request.OrganizationPageQueryRequest;
import com.ethink.system.api.request.OrganizationQueryRequest;
import com.ethink.system.api.request.OrganizationUpdateRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统组织机构表 Controller
 *
 * @author default
 * @date 2022-09-26
 */
@Tag(name = "SystemOrganizationController", description = "系统组织机构表 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/system-service")
public class SystemOrganizationController extends BaseController {

    @Autowired
    private SystemOrganizationFacade systemOrganizationFacade;

    @Operation(summary = "分页查询")
    @GetMapping("/systemOrganization/pageQuery")
    public CommonResponse<List<SystemOrganizationInfo>> pageQuerySystemOrganization(OrganizationPageQueryRequest request) {
        return succeedWithPage(systemOrganizationFacade.pageQuerySystemOrganization(request));
    }

    @Operation(summary = "根据Id查询")
    @GetMapping("/systemOrganization/get/{systemOrganizationId}")
    public CommonResponse<SystemOrganizationInfo> getSystemOrganizationById(@PathVariable("systemOrganizationId") Long systemOrganizationId) {
        return succeedWith(systemOrganizationFacade.getSystemOrganizationById(systemOrganizationId));
    }

    @Operation(summary = "新增组织")
    @PostMapping("/systemOrganization/add")
    public CommonResponse systemOrganizationAdd(@Validated @RequestBody OrganizationAddRequest request) {
        systemOrganizationFacade.add(request);
        return succeed();
    }

    @Operation(summary = "更新组织")
    @PutMapping("/systemOrganization/update")
    public CommonResponse systemOrganizationUpdate(@Validated @RequestBody OrganizationUpdateRequest request) {
        systemOrganizationFacade.update(request);
        return succeed();
    }

    @Operation(summary = "查询所有组织")
    @GetMapping("/systemOrganization/list")
    public CommonResponse<List<SystemOrganizationInfo>> systemOrganizationGetAll(OrganizationQueryRequest request) {
        return succeedWith(systemOrganizationFacade.systemOrganizationGetAll(request));
    }

    @PutMapping("/systemOrganization/delete/{id}")
    @Operation(summary = "删除组织")
    public CommonResponse systemOrganizationDelete(@PathVariable("id") Long id) {
        systemOrganizationFacade.systemOrganizationDelete(id);
        return succeed();
    }
}